﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dicide.ViewModels
{
    public class CornerViewModel : ConductorViewModel
    {
        public override void UpdateHasConnectors()
        {
            if (Rotation == 0)
            {
                HasLeftConnector = true;
                HasTopConnector = true;
                HasRightConnector = false;
                HasBottomConnector = false;
            }
            else if (Rotation == 90)
            {
                HasLeftConnector = false;
                HasTopConnector = true;
                HasRightConnector = true;
                HasBottomConnector = false;
            }
            else if (Rotation == 180)
            {
                HasLeftConnector = false;
                HasTopConnector = false;
                HasRightConnector = true;
                HasBottomConnector = true;
            }
            else if (Rotation == 270)
            {
                HasLeftConnector = true;
                HasTopConnector = false;
                HasRightConnector = false;
                HasBottomConnector = true;
            }
        }

        protected override IEnumerable<ConductorViewModel> NeighboringConductors()
        {
            var left = Left as ConductorViewModel;
            var top = Top as ConductorViewModel;
            var right = Right as ConductorViewModel;
            var bottom = Bottom as ConductorViewModel;

            if (Rotation == 0)
            {
                right = null;
                bottom = null;
            }
            else if (Rotation == 90)
            {
                bottom = null;
                left = null;
            }
            else if (Rotation == 180)
            {
                left = null;
                top = null;
            }
            else if (Rotation == 270)
            {
                top = null;
                right = null;
            }

            if (left != null && left.HasRightConnector) yield return left;
            if (top != null && top.HasBottomConnector) yield return top;
            if (right != null && right.HasLeftConnector) yield return right;
            if (bottom != null && bottom.HasTopConnector) yield return bottom;
        }
    }
}
